#!/bin/bash
###
 # @Description: 阻止代码中debugger、console.log、alert关键词的提交
 # @Author: laoyuan
 # @Date: 2023-06-04 23:43:53
###

red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`
# echo "${red}red text ${green}green text${reset}"

echo  "${green}开始检测关键词${reset}"

for FILE in `git diff --name-only --cached`; do

    # 忽略的目录文件
    if [[ $FILE =~ 'build/' ]] || [[ $FILE =~ 'husky/' ]] || [[ $FILE =~ '.md' ]] || [[ $FILE =~ '.cjs' ]]; then

        echo $FILE "忽略此类文件内容"
        continue

    else

      grep 'TODO:\|debugger\|console.log\|alert(' $FILE 2>&1 >/dev/null
      if [ $? -eq 0 ]; then

          echo $FILE '包含，TODO: or debugger or console.log，请删除后再提交哈'
          exit 1

      fi

    fi
done
exit
